package create.factory.method;

import create.factory.simple.IComputer;

/**
 * Created by lie on 2017/10/30.
 * 具体工厂
 * 这里又要对比{@link create.factory.simple.ComputerFactory}，这里同样不会写死要生产的类型
 *
 * 这样当增加更多的产品的时候，这个类完全不需要改
 */
public class GDComputerFactory extends IComputerFactory{

    @Override
    public <T extends IComputer> T createComputer(Class<T> clazz) {
        IComputer computer = null;
//        String clazzName = clazz.getName();
        try {
            computer = clazz.newInstance();
//            computer = (IComputer) Class.forName(clazzName).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
//        catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }

        return (T)computer;
    }
}
